package com.cskaoyan.controller;

import com.cskaoyan.bean.BaseRespVo;
import com.cskaoyan.bean.bo.CategoryCreateBO;
import com.cskaoyan.bean.bo.CategoryDeleteBO;
import com.cskaoyan.bean.bo.CategoryUpdateBO;
import com.cskaoyan.bean.pojo.MarketCategory;
import com.cskaoyan.bean.vo.CategoryCreateVO;
import com.cskaoyan.bean.vo.CategoryL1VO;
import com.cskaoyan.bean.vo.CategoryListVo;
import com.cskaoyan.service.CategoryService;
import com.fasterxml.jackson.databind.ser.Serializers;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.bind.annotation.RestController;

/**
 * @author rebaogu
 * @description 商品类目功能
 * @date 2022.04.06 19:54
 * @package com.cskaoyan.controller
 * @Classname CategoryController
 */
@RestController
@RequestMapping("admin/category")
public class MarketCategoryController {
    // MarketCategory marketCategory = new MarketCategory();

    @Autowired
    CategoryService categoryService;

    // 首页获取
    @RequestMapping("list")
    public BaseRespVo categoryList() {
        CategoryListVo categoryListVo = categoryService.categoryList();
        return BaseRespVo.ok(categoryListVo);
    }
    // 首页获取 --> 类目名
    @RequestMapping("l1")
    public BaseRespVo categoryL1() {

        CategoryL1VO categoryL1 = categoryService.categoryL1();
        return BaseRespVo.ok(categoryL1);

    }
    // 新建类目
    @RequestMapping("create")
    public BaseRespVo categoryCreate(@RequestBody CategoryCreateBO categoryCreateBO) {
        CategoryCreateVO categoryCreateVO = categoryService.categoryCreate(categoryCreateBO);

        return BaseRespVo.ok(categoryCreateVO);
    }
    // 更新类目
    @RequestMapping("update")
    public BaseRespVo categoryUpdate(@RequestBody CategoryDeleteBO categoryUpdateBO) {

        categoryService.categoryUpdate(categoryUpdateBO);
        return BaseRespVo.ok();
    }


    // 删除类目
    @RequestMapping("delete")
    public BaseRespVo categoryDelete(@RequestBody CategoryDeleteBO categoryDeleteBO) {
        categoryService.categoryDelete(categoryDeleteBO);

        return BaseRespVo.ok();

    }

}
